package com.explore.demo.controller;


import com.explore.demo.common.ServerResponse;
import com.explore.demo.pojo.Comment;
import com.explore.demo.service.CommentService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author gaolainan
 * @since 2021-04-14
 */
@RestController
@RequestMapping("/comment")
public class CommentController {

    @Resource
    private CommentService commentService;

    @GetMapping
    @ApiOperation("查询全部的评论")
    public ServerResponse query(){
        return commentService.queryAll();
    }

    @PostMapping
    @ApiOperation("创建一个评论")
    public ServerResponse addOne(@RequestBody Comment comment, HttpServletRequest request){
        return commentService.addComment(comment, request);
    }

    @DeleteMapping
    @ApiOperation("通过招聘信息的id 删除相关的的评论")
    public ServerResponse deleteByRecruitId(String recruitId){
        return commentService.deleteCategoryByRecruitId(recruitId);
    }

    @PostMapping("/{recruitId}")
    @ApiOperation("通过招聘信息的id 查询评论的相关信息")
    public ServerResponse queryByRecruitId(@PathVariable("recruitId") String recruitId){
        return commentService.queryCommentByRecruitId(recruitId);
    }

    @PutMapping
    @ApiOperation("更新评论信息")
    public ServerResponse updateComment(@RequestBody Comment comment){
        return commentService.updateComment(comment);
    }
}

